﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using LyyCMS.Core;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;

namespace LyyCMS.Web.Areas.Dash.Controllers
{
    [Area("Dash")]
    [Route("Dash/[controller]/[action]")]
    public class UsersController : BaseController
    {

        public UsersController(ILogger<BaseController> loggger, LyyCMS.Core.LyyCMSEntities lyyCMSEntities) : base(loggger, lyyCMSEntities)
        {
        }


        public IActionResult Index(int page=1)
        {

            List<Core.Models.User> users = _context.Users
                .OrderByDescending(x => x.Id)   //创建时间倒序
                .Skip((page - 1) * pagesize)         //截取数据
                .Take(pagesize)                      //取pagesize条数据
                .ToList();


            int count = 1; //总页数
            count = _context.Users.Count() / 5;
            count += _context.Users.Count() % 5 > 0 ? 1 : 0;

            ViewBag.pagecount = count;
            ViewBag.currentpage = page;

            ViewBag.preview = page > 1 ? page - 1 : page;
            ViewBag.nextpage = page >= count ? count : count + 1;
            return View(users);
        }
    }
}